<?php


namespace plugin\coleopenapi\app\logic;


use app\common\logic\BaseLogic;
use plugin\coleopenapi\app\model\OpenapiApi;
use support\utils\CacheUtil;

class ApiLogic extends BaseLogic
{
    const API_INFO = "openapi:api_info";

    public function __construct()
    {
        $this->model = new OpenapiApi();
    }

    public function getApiByMethod($method)
    {
        return CacheUtil::tag(self::API_INFO)->remember(self::API_INFO . ':' . $method, function () use ($method) {
            $data = $this->model->where('method', $method)->find();
            return $data ? $data->toArray() : [];
        }, 24 * 60 * 60);
    }

    public function removeCache()
    {
        return CacheUtil::tag(self::API_INFO)->clear();
    }


}